package com.example.demo;

import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Calendar;
import java.util.List;

public class Test1 {
    public static void main(String[] args) {

        //延迟3秒
        Calendar cal1 = Calendar.getInstance();
        cal1.add(Calendar.SECOND, 3);
        int second3later = (int) (cal1.getTimeInMillis() / 1000);
        System.out.println(second3later);
        Calendar cal11 = Calendar.getInstance();
        cal11.add(Calendar.SECOND, 6);
        int second6later = (int) (cal11.getTimeInMillis() / 1000);
        System.out.println(second6later);

        //1.创建Calendar类对象，不能new
        Calendar cal= Calendar.getInstance();
        //打印出当前日期
        System.out.println(cal.getTime().toLocaleString());
        //获取毫秒值
        System.out.println(cal.getTimeInMillis());

        //2.获取时间信息
        //获取年
        int year=cal.get(Calendar.YEAR);//里面的参数可以用1代替
        //获取月
        int month=cal.get(Calendar.MONTH);//里面的参数可以用2代替
        //获取日
        int day=cal.get(Calendar.DAY_OF_MONTH);//
        //获取小时，Hour表示12小时，HOUR_OF_DAY表示24小时
        int hour=cal.get(Calendar.HOUR_OF_DAY);//里面参数可以用11代替
        //获取分钟
        int minute=cal.get(Calendar.MINUTE);//里面参数可以用12表示
        //获取秒
        int second=cal.get(Calendar.SECOND);//里面参数可以用13表示
        System.out.println(year+"年"+(month+1)+"月"+day+"日"+hour+"时"+minute+"分"+second+"秒");

        //3.修改时间
        Calendar cal2=Calendar.getInstance();
        cal2.getInstance().set(Calendar.DAY_OF_MONTH,5);
        System.out.println(cal2.getTime().toString());

        //4.add方法修改时间
        cal2.add(Calendar.HOUR_OF_DAY,-1);
        System.out.println(cal2.getTime().toLocaleString());

        //5.补充方法，获取最大最小值
        int max=cal2.getActualMaximum(Calendar.HOUR_OF_DAY);
        int min=cal2.getActualMinimum(Calendar.HOUR_OF_DAY);
        System.out.println(max);
        System.out.println(min);
        System.out.println(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(cal.getTime()));

    }
}
